package com.common.vo.dd;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("钉钉资讯卡Vo")
public class DingDingFeedCardVo {

    private String msgType;

    private List<BaseLinkVo> links;

    public String getJSONObjectString() {

        // text类型
        JSONObject feedCardContent = new JSONObject();
        List<BaseLinkVo> links = Lists.newArrayList();
        for (int i = 0; i < this.getLinks().size(); i++) {
            links.add(this.getLinks().get(i));
        }
        if (this.getLinks().size() > 0) {
            feedCardContent.put("links", links);
        }

        JSONObject json = new JSONObject();
        json.put("msgtype", this.getMsgType());
        json.put("feedCard", feedCardContent);

        return json.toJSONString();
    }
}